package com.hxd.otc.module.order.presenter;

import android.support.annotation.NonNull;

import com.hxd.otc.base.BaseBean;
import com.hxd.otc.module.order.activity.BuyOrderDetailActivity;
import com.hxd.otc.module.order.bean.AllOrderBean;
import com.hxd.otc.module.order.bean.BankInfoPoData;
import com.hxd.otc.module.order.contract.BuyOrderDetailContract;
import com.hxd.otc.module.order.model.AllOrderModel;
import com.hxd.otc.mvp.base.BasePresenter;
import com.hxd.otc.net.BaseObserver;

import java.util.List;

/**
 * 作  者 :  zjl
 * 时  间 :  2018/6/9 12:02
 * 描  述 :  ${订单完成}
 */
public class BuyOrderDetailPresenter extends BasePresenter<BuyOrderDetailContract.View> implements BuyOrderDetailContract.Presenter {

    AllOrderModel model;

    public BuyOrderDetailPresenter(BuyOrderDetailContract.View view) {
        super(view);
        model = AllOrderModel.getInstance();
    }

    @Override
    public void doLoadData(String... category) {

        model.getOrderDetailData(new BaseObserver<AllOrderBean.DataBean>() {
            @Override
            public void onNext(String title, AllOrderBean.DataBean bean) {

                doShowNoMore();
                mView.onSetData(bean);
            }

            @Override
            public void onError(int errType, String errMessage) {
                doShowNoMore();
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean<AllOrderBean.DataBean>>bindAutoDispose(), category[0]);

    }

    @Override
    public void getOrderBankList(String... category) {
        model.getOrderBankList(new BaseObserver<List<BankInfoPoData>>() {
            @Override
            public void onNext(@NonNull String msg, @NonNull List<BankInfoPoData> bankInfoPoData) {

                mView.getBankList(bankInfoPoData);
            }

            @Override
            public void onError(int errType, @NonNull String errMessage) {

            }

        }, mView.<BaseBean<List<BankInfoPoData>>>bindAutoDispose(), category);
    }

    @Override
    public void doShowNoMore() {
        mView.onHideLoading();
    }

    @Override
    public void cancleDetal(String... category) {

        model.cancleDetal(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {
                mView.refreshView(BuyOrderDetailActivity.CANCLE_DETAL_SUCCESS);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }

        }, mView.<BaseBean>bindAutoDispose(), category[0],category[1]);
    }

    @Override
    public void paying(final String... category) {

        model.paidOrder(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {
                mView.paidOrderSuccess(category[1]);
                mView.refreshView(BuyOrderDetailActivity.PAYIING_SUCCESS);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
                mView.onError(errType);
            }


        }, mView.<BaseBean>bindAutoDispose(), category[0], category[1],category[2],category[3]);

    }

    @Override
    public void withdrawalRep(String... category) {

        model.recallOrder(new BaseObserver() {
            @Override
            public void onNext(String title, Object bean) {
                mView.refreshView(BuyOrderDetailActivity.WITHDRAW_SUCCESS);
            }

            @Override
            public void onError(int errType, String errMessage) {
                mView.showToast(errMessage);
            }


        }, mView.<BaseBean>bindAutoDispose(), category[0]);
    }
}
